
// 商品分类一级列表
function navClu(){
    let navDataUl = document.getElementById('navDataUl');
    axios({
        url:"/home/index/showBigType",
        method:"GET",

    })
    .then(data=>{
        navDataUl.innerHTML = ''
        for(let i = 0;i<data.data.data.length;i++){
            navDataUl.innerHTML += `
            <li class="LI">${data.data.data[i].btype}</li>
            `
            
        }
        let LI =document.getElementsByClassName('LI')
        for(let i=0;i<LI.length;i++){
            LI[i].addEventListener('mouseover', function(){
                detailsGoods(i+1)
            })
        }
    })
    .catch(err=>{
        console.log(err);
    })
}
navClu()

//商品分类二级列表
function detailsGoods(e){ 
    // e.toString()
    // e=e || window.event;
    // var target=e.target || e.srcElement;
    // bigId=target.getAttribute("target")
    let containerDetailsGoods = document.getElementsByClassName('containerDetailsGoods')[0]
    axios({
        url:'/home/index/getAllTypesByBigId',
        method:"GET",
        params:{
            bigId:e
        }
    })
    .then(data => {
        // console.log(e);
        // console.log(data.data);
        containerDetailsGoods.innerHTML=` `
        for(let i=0;i<data.data.data.length;i++){
            // console.log(data.data.data[i].name);
            // console.log(data.data.data[i].data.length);
            containerDetailsGoods.innerHTML +=`
                <dl>
                    <dt>${data.data.data[i].name}</dt>
                    <dd class='hello'></dd>
                </dl>
            `
            for(let j = 0; j<data.data.data[i].data.length; j++){                                                                          
               let str1='';
               str1+=`
                <a href="">${data.data.data[i].data[j].ltype}</a>  
               `
               document.getElementsByClassName('hello')[i].innerHTML += str1;
            }  
           
        }
        
        
        
                
    })
    .catch(err => {
        console.log(err);
    })
}

//商品分类三级列表
function detailsGoodsThree(e){
    let containerDetailsGoods = document.getElementsByClassName('containerDetailsGoods')[0]
    let threeA = containerDetailsGoods.querySelectorAll('dl dd')
    // console.log(threeA);
    axios({
        url:'/home/index/showLittleType',
        method:'GET',
        params:{
            mediumId:e
        }
    })
    .then(data => {
            threeA.innerHTML=` `
            for(let i=0;i<data.data.data.length;i++){
                threeA.innerHTML +=`
                
                        <a href="">${data.data.data[i].ltype}</a>
                   
                `
            }
        // }
    })
    .catch(err => {
        console.log(err);
    })
}
// detailsGoodsThree()


//搜索
let searchBtn = document.getElementsByClassName('searchBtn')[0]

searchBtn.addEventListener('click',function(){
    // console.log(111);
    let value = document.getElementsByClassName('searchInput')[0].value
    let setting = document.getElementsByClassName('sort')[0].innerHTML
    // console.log(setting);
    // console.log(value);
    if(setting == '宝贝'){
        window.location.href = `/home/search?content=${value}&setting=${setting}`
    }else if(setting =='店铺'){
        window.location.href = `/home/searchShop?content=${value}&setting=${setting}`
    }
    
})

let userId
if(document.getElementsByClassName('cartTotal')[0]){
    userId = document.getElementsByClassName('cartTotal')[0].getAttribute('userId')
}

// 侧边栏用户购物车总数
function cartTotal(){
    
    // console.log(userId);
    axios({
        url:'/home/shoppingCart/queryCartCountByUserId',
        method:'GET',
        params:{
            userId: userId
        }
    })
    .then(data => {
        console.log(111111111111);
        console.log(data);
        document.getElementsByClassName('cartTotal')[0].innerHTML = data.data.data.data
    })
    .catch(err => {
        console.log(err);
    })
}
cartTotal()

//主导航条类别
function mainNavClassify(){
    // console.log(1111);
    let linkLi = document.getElementsByClassName('linkLi')
    for(let i = 1; i<linkLi.length; i++){
        linkLi[i].addEventListener('click', function(){
            for(let j=1; j<linkLi.length; j++){
                linkLi[j].classList.remove('linkWeight')
            }
            linkLi[i].classList.add('linkWeight')
        })
    }
}
mainNavClassify()

// 删除成功
let timerExplain
function explain({code,msg,time}){
    let explainIcon = document.getElementById("explainIcon");
    let explainMsg = document.getElementsByClassName("SuDeleteGoodsInner")[0];
    let explain = document.getElementsByClassName("SuPopBox")[0];
    clearInterval(timerExplain);
    explain.style.display="block";
    explain.style.visibility="visible"
    explain.style.opacity = "1"
    if(code==1){
        explainIcon.setAttribute("class","iconfont chenggong");
    }else if(code==2){
        explainIcon.setAttribute("class","iconfont shibai");
    }else if(code==3){
        explainIcon.setAttribute("class","iconfont jinggao");
    }else{
        alert("参数错误");
        explain.style.display="none";
        return false;
    }
    explainMsg.innerHTML = msg;
    timerExplain= setInterval(function(){ 
        explain.style.display="none";
        explain.style.visibility="hidden"
        explain.style.opacity = "0"
    },time)
}